package com.example.controller;
import com.example.common.Result;
import com.example.common.ResultUtils;
import com.example.dto.Job;
import com.example.dto.JobCreateRequest;
import com.example.dto.JobUpdateRequest;
import com.example.service.JobService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/*
@description:定时任务
@ClassName JobController
@author chen
@create 2025-07-09 16:47
@Version 1.0
*/
@RestController
@RequestMapping("job")
public class JobController
{
    @Resource
    private JobService jobService;


    /*
     * @param request
     * @==============History===============<br/>;
     * @Description //   创建job
     * @Date 2025/7/9
     */
    @PostMapping("/jobCreate")
    public Result<String> jobCreate(@RequestBody JobCreateRequest request)
    {
        return ResultUtils.ok(this.jobService.jobCreate(request));
    }


    /*
     * @param request
     * @==============History===============<br/>;
     * @Description //   更新job
     * @Date 2025/7/9
     */
    @PostMapping("/jobUpdate")
    public Result<Boolean> jobUpdate(@RequestBody JobUpdateRequest request)
    {
        return ResultUtils.ok(this.jobService.jobUpdate(request));
    }


    /*
     * @param id
     * @==============History===============<br/>;
     * @Description //   删除job
     * @Date 2025/7/9
     */
    @PostMapping("/jobDelete")
    public Result<Boolean> jobDelete(@RequestParam("id") String id)
    {
        return ResultUtils.ok(this.jobService.jobDelete(id));
    }


    /*
     * @param id
     * @==============History===============<br/>;
     * @Description //   启用job
     * @Date 2025/7/9
     */
    @PostMapping("/jobStart")
    public Result<Boolean> jobStart(@RequestParam("id") String id)
    {
        return ResultUtils.ok(this.jobService.jobStart(id));
    }



    /*
     * @param id
     * @==============History===============<br/>;
     * @Description //  停止job
     * @Date 2025/7/9
     */
    @PostMapping("/jobStop")
    public Result<Boolean> jobStop(@RequestParam("id") String id)
    {
        return ResultUtils.ok(this.jobService.jobStop(id));
    }



    /*
     * @==============History===============<br/>;
     * @Description //   获取所以的job任务
     * @Date 2025/7/9
     */
    @GetMapping
    public Result<List<Job>> jobList()
    {
        return ResultUtils.ok(this.jobService.jobList());
    }

}
